package com.matezk.sael;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.LinearLayout;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;

import java.util.ArrayList;
import java.util.List;

public class SystemActivity extends AppCompatActivity implements View.OnClickListener {
    private static final String TAG = SystemActivity.class.getSimpleName();

    private List<Button> buttonGroup = new ArrayList<>();

    private Button backBtn;
    private Button setBtn;
    private Button logBtn;
    private Button pitBtn;
    private Button aboutBtn;

    private LinearLayout systemLayout;
    private FrameLayout frameLayout;



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.layout_system);

        // 右侧容器
        frameLayout = findViewById(R.id.system_frame_container);

        systemLayout = findViewById(R.id.layout_system);
        // 设置点击空白区域关闭软键盘
        systemLayout.setOnClickListener(v -> {
            InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
        });
        backBtn = findViewById(R.id.system_btn_back);
        buttonGroup.add(backBtn);
        setBtn = findViewById(R.id.system_btn_set);
        buttonGroup.add(setBtn);
        logBtn = findViewById(R.id.system_btn_log);
        buttonGroup.add(logBtn);
        pitBtn = findViewById(R.id.system_btn_pit);
        buttonGroup.add(pitBtn);
        aboutBtn = findViewById(R.id.system_btn_about);
        buttonGroup.add(aboutBtn);

        FragmentManager fragmentManager = getSupportFragmentManager();
        FragmentTransaction transaction = fragmentManager.beginTransaction();
        SettingsFragment pageOne = new SettingsFragment();
        transaction.add(R.id.system_frame_container, pageOne);
        transaction.commit();
    }

    @Override
    public void onClick(View view) {
        for (Button button : buttonGroup) {
            if (button.getId() == view.getId()) {
                button.setBackgroundColor(Color.parseColor("#005B70"));
            } else {
                button.setBackgroundColor(Color.parseColor("#00707B"));
            }
        }
        switch (view.getId()) {
            case R.id.system_btn_back:
                Intent intent = new Intent(SystemActivity.this, MainActivity.class);
                startActivity(intent);
                finish();
                break;
            default:
                break;
        }
    }
}